function updateSchedule(id)
{
	alert("You don't have permission !");
}
function updateSalary(id)
{
	alert("You don't have permission !");
}
function calc_hours_salary(id)
{
	var scaled_hours = 0;
	var total_hours = 0;
	var salary = 0;
	var ratio = {
			"first_shift":2
			,"last_shift":1.5
			,"weekend":2
			,"last_shift_weekend":2.5
	};
	
	var hours_per_shift = 4;
	var salary_per_shift = document.getElementById("salary_shift_"+id).value;
	
	for (var x=0;x<4;x++)
	{
		for (var y=0;y<7;y++)
		{
			if(document.getElementById("s_"+id+"_"+x+"_"+y).checked)
			{
				//total_hours
				if(x == 0)
					total_hours += 8;
				else
					total_hours += 4;

				//scaled hours
				if(x == 0 && (y == 5 || y == 6))
					scaled_hours = scaled_hours + hours_per_shift * ratio["first_shift"] * ratio["weekend"];
				else if(x == 3 && (y == 5 || y == 6))
					scaled_hours = scaled_hours + hours_per_shift * ratio["last_shift_weekend"];
				else if(x == 0)
					scaled_hours = scaled_hours + hours_per_shift * ratio["first_shift"];
				else if(x == 3)
					scaled_hours = scaled_hours + hours_per_shift * ratio["last_shift"];
				else if(y == 5 || y == 6)
					scaled_hours = scaled_hours + hours_per_shift * ratio["weekend"];
				else
					scaled_hours = scaled_hours + hours_per_shift;
			}					
		}
	}
	if(document.getElementById("choose_salary_shift_"+id).checked)
	{		
			salary = salary_per_shift * scaled_hours/4;
			document.getElementById("salary_week_"+id).value = salary;
	}
	document.getElementById("total_hours_"+id).value = total_hours;
	document.getElementById("scaled_hours_"+id).value = scaled_hours;
}
function chooseKindOfSalary(id)
{
	if(document.getElementById("choose_salary_shift_"+id).checked)
	{
		document.getElementById("salary_shift_"+id).disabled = false;
		document.getElementById("salary_month_"+id).disabled = true;
		document.getElementById("salary_week_"+id).readOnly = true;
		document.getElementById("salary_week_"+id).disabled = false;
		document.getElementById("salary_month_"+id).value = "";
	}
	else
	{
		document.getElementById("salary_shift_"+id).disabled = true;
		document.getElementById("salary_month_"+id).disabled = false;
		document.getElementById("salary_week_"+id).disabled = true;
		document.getElementById("salary_shift_"+id).value = "";
		document.getElementById("salary_week_"+id).value = "";
	}
}
function show_ar()
{
	$("#loading-mask").css('display', '');
	$("#loading-msg").css('display', '');
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

	var url = document.getElementById("ajax_url").value + "?op=show_ar";

	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
				$("#loading-mask").css('display', 'none');
				$("#loading-msg").css('display', 'none');
				document.getElementById("dayoff").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
function submit_ar()
{
        $("#loading-mask").css('display', '');
        $("#loading-msg").css('display', '');
	if(window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else
	{
		xlmhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	var url = document.getElementById("ajax_url").value + "?op=submit_ar";
	url = url + "&adminid="+document.getElementById("adminid").value;
	url = url + "&shiftid="+document.getElementById("shiftid").value;
	url = url + "&day="+document.getElementById("day").value;
	url = url + "&month="+document.getElementById("month").value;
	url = url + "&year="+document.getElementById("year").value;
	url = url + "&reason="+document.getElementById("reason").value;
	url = url + "&replacement="+document.getElementById("replacement").value;

	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4)
		{
                        $("#loading-mask").css('display', 'none');
                        $("#loading-msg").css('display', 'none');
			if(xmlhttp.responseText == 1)
			{
                                document.getElementById("dayoff").innerHTML = "<font color='green'><b>Submit Successfully.</b></font>";
				
			}
			else
			{
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.send("null");
}
function show_pr()
{
	$("#loading-mask").css('display', '');
	$("#loading-msg").css('display', '');
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

	var url = document.getElementById("ajax_url").value + "?op=show_pr";

	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
				$("#loading-mask").css('display', 'none');
				$("#loading-msg").css('display', 'none');
				document.getElementById("dayoff").innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send(null);
}
function delRequest(adminid,date,shiftid)
{
	$("#loading-mask").css('display', '');
	$("#loading-msg").css('display', '');
	if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
	else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
	
	var url = document.getElementById("ajax_url").value + "?op=delRequest";
		url = url + "&adminid=" + adminid;
		url = url + "&date=" + date;
		url = url + "&shiftid=" + shiftid;

	xmlhttp.open("GET",url,true);
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			$("#loading-mask").css('display', 'none');
			$("#loading-msg").css('display', 'none');
			if (xmlhttp.responseText!="1")      
			{
				alert(xmlhttp.responseText);
			}
		}
	}
	xmlhttp.send(null);
}